'''Database manager.'''

__author__ = 'mengyanwei'

from collections import OrderedDict
from pymongo import MongoClient
from pymongo.database import Database

class BaseDBer(Database):
    '''Basic database manager.'''
    pass

class MongoDBer(BaseDBer):
    '''Mongodb manager.'''

    def __init__(self, conf, **kwargs):
        ''' conf: a dict type, contain basic info
        '''
        assert isinstance(conf, dict)
        self.host = conf['host']
        self.port = conf['port']
        self.database = conf['database']
        self.user = conf['user']
        self.password = conf['password']
        self.connection = MongoClient(self.host, self.port, document_class=OrderedDict, **kwargs)
        print('MonGo连接池对象创建成功')
        super(MongoDBer, self).__init__(self.connection, self.database)
        self.authenticate(name=self.user, password=self.password)

    def __del__(self):
        pass
